﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RecommenderSystem.misc;

namespace RecommenderSystem.algorithms.popularityBased
{
    class Popularity:PopularityBased
    {
        private Dictionary<string, int> popularItems;
        public Popularity(Dictionary<string, User> users, ICollection<IDataRecord> dataset) : base(users, dataset) 
        {
            popularItems = new Dictionary<string, int>();

            string itemId;
            foreach (var record in dataset)
            {
                itemId = record.getItemID();

                if (!popularItems.ContainsKey(itemId))
                {
                    popularItems.Add(itemId, 0);
                }
                popularItems[itemId]++;
            }

        }

        /**
         * Item rating is defined by the number of times that this item was 
         * rated by all users in DB.
         * 
         */ 
        public override double predictRating(string userID, string itemID)
        {
            if (popularItems.ContainsKey(itemID))
            {
                return popularItems[itemID];
            }

            return 0d ;
        }
    }
}
